#include "LogSaver.h"

#include "FileWriter.h"

LogSaver::LogSaver(QObject* parent) :QObject(parent)
{
}
LogSaver::~LogSaver()
{
}
void LogSaver::slot_log(QString msg, LogFlag logFlag)
{
	if (logLevel & logFlag)
	{
		QString log = QDateTime::currentDateTime().toString("yyyy.MM.dd.hh:mm:ss")+getQStringOfLogFlag(logFlag) + msg + newLine;
		fileWriter->saveAsFile<LogSaver>(logFilePath, log.toLocal8Bit(), FileWriter::AppendToFile);
	}
}

void LogSaver::enableLogLevel(LogFlag logFlag)
{
	logLevel |= logFlag;
}
void LogSaver::disableLogLevel(LogFlag logFlag)
{
	logLevel &= (~logFlag);
}

QString LogSaver::getQStringOfLogFlag(LogFlag logFlag)
{
	switch (logFlag)
	{
	case LogSaver::Debug:
		return QString_debug;
	case LogSaver::Information:
		return QString_information;
	case LogSaver::Warning:
		return QString_warning;
	case LogSaver::Critical:
		return QString_critical;
	default:
		return "";
	}
}
int LogSaver::getLogLevel()
{
	return logLevel;
}
QString LogSaver::getLogFilePath()
{
	return logFilePath;
}

void LogSaver::setLogFilePath(QString filePath)
{
	this->logFilePath = filePath;
}
FileWriter* LogSaver::getFileWriter()
{
	return  fileWriter;
}
void LogSaver::setFileWriter(FileWriter* fileWriter)
{
	this->fileWriter = fileWriter;
}
